package Administrator;

import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.rmi.RMISecurityManager;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

import javax.rmi.ssl.SslRMIClientSocketFactory;
import javax.rmi.ssl.SslRMIServerSocketFactory;

import General.ProxyInterface;
import General.ShipInterface;

public class Main {
	public static void main(String[] args) {
		try {
 			//System.setProperty("java.security.policy", "Policies/administrator.policy");
	        //System.setProperty("javax.net.ssl.trustStore", "Policies/AdministratorTrustStore");
	        //System.setProperty("javax.net.ssl.keyStore", "Policies/AdministratorKeyStore");
	        //System.setProperty("javax.net.ssl.keyStorePassword", "nieldeckx");
	        
			if(System.getSecurityManager() == null) {
				System.setSecurityManager(new RMISecurityManager());
			}
	        
	        String address = "localhost";
	        int port = 1099;
	        
	        if (args.length > 0)
	        	address = args[0];
	        if (args.length > 1)
	        	port =  Integer.valueOf(args[1]);
	        
			Registry registry = LocateRegistry.getRegistry(address, port);
			Registry registryImplementation = (Registry)registry.lookup("RegistryImplementation");
			ProxyInterface proxyInterface = (ProxyInterface) registryImplementation.lookup("ClientProxy");
			
			System.out.println("[Administrator] Administrator changed rates.");
			proxyInterface.changeRates(30, 60, 80);
			
			System.out.println("");
			System.out.println("[Administrator] Administrator serialize server to file.");
			ShipInterface shipInterface = proxyInterface.getServer(0);
			String file = shipInterface.serialize();
			
			System.out.println("");
			System.out.println("[Administrator] Administrator deserialize server.");
			ShipInterface shipInterface1 = shipInterface.deserialize(file);
			registryImplementation.rebind("Server_1", shipInterface1);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
